<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/pintuer.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/admin.css">
<script src="${pageContext.request.contextPath}/static/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/static/js/pintuer.js"></script>
<script type="text/javascript" src="../static/plugin/zTree_v3/js/jquery-1.4.4.min.js"></script>
<link rel="stylesheet" type="text/css" href="../static/plugin/zTree_v3/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript" src="../static/plugin/zTree_v3/js/jquery.ztree.all.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	 $("form").submit(function(e){
			var ids = [], nodes = tree.getCheckedNodes(true);
			for(var i=0; i<nodes.length; i++) {
				ids.push(nodes[i].id);
			}
			$("#menuIds").val(ids);
			loading('正在提交，请稍等...');
			form.submit();
		}) 
	

	var setting = {
		   /*  "check": {
		        "enable": true,
		        "nocheckInherit": true
		    }, */
		    "view": {
		        "selectedMulti": false
		    },
		    "data": {
		        "simpleData": {
		            "enable": true
		        }
		    },
		    "callback": {
		    	onClick: zTreeOnClick
		    }
		};
	
	// 用户-菜单
	
	var zNodes= eval('${areaList}');
	// 初始化树结构
	var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
	// 不选择父节点
	tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
	setInterval(()=>{
		var treeObj = tree.getCheckedNodes();
		//var nodes = treeObj.getCheckedNodes(true);
		console.log(treeObj);
	},2000); 
	// 默认选择节点
	var ids = "".split(",");
	for(var i=0; i<ids.length; i++) {
		var node = tree.getNodeByParam("id", ids[i]);
		try{tree.checkNode(node, true, false);}catch(e){}
	}
	// 默认展开全部节点
	tree.expandAll(true);

})
function zTreeOnClick(event, treeId, zNodes) {
		var Mname = zNodes.name;
		var Mid = zNodes.id;
		$("#pname").val(Mname);
		$("#pid").val(Mid);
	    alert(Mid + ", " + Mname);
	    
	};

</script>
<script type="text/javascript">
//异步检验账号是否存在
function doVerify(){
    //获取界面的账号
    var medicalname =  $("#medicalname").val();
    /* alert(account) */
    //获取账号后的提示信息文本
   /*  var accountText = document.getElementById("accountText"); */
    //如果账号输入不为空，执行该方法
    if(medicalname !=""){
        $.ajax({
            url:"${pageContext.request.contextPath}/sys/medicalI.do?method=CheckNameExist",//后台查询验证的方法
            data:{"medicalname": medicalname},//携带的参数
            type: "post",
            success: function(msg){
                //根据后台返回前台的msg给提示信息加HTML
                if("true" !=msg){
                	display.innerHTML = "<font color='#e33'>"+medicalname+"已存在！</font>"
                	}
                else{
                	 // 账号不存在
                    display.innerHTML = "<font color='#61daa5'>"+medicalname+"可以使用！</font>"
                }
                }
              

            /* success: function(data){
            	 var result = jQuery.parseJSON(data);
                 $('#display b').text(result.res);
            } */
        });
    }
}

</script>
</head>
<body>

<div class="panel admin-panel">

  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加医疗机构</strong></div>
  <div id="menuTree" class="ztree" style="margin-top:3px;float:left;"></div>
  <div class="body-content">
  
    <form method="post" class="form-x" action="${pageContext.request.contextPath}/sys/area.do?method=addAreaInfo&tgId=${tgId}&pageNum=1">  
    	
      <div class="form-group">
      	
        <div class="label">
          <label>上一级行政区域</label>
        </div>
        
        <div class="field">
          <input type="text" class="input w50" value="" name="pname" data-validate="required:请选择上一级行政机构" id="pname"/>
          <input type="hidden"  name="pid"id="pid"/>
          <div class="tips"></div>
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label>行政区域名称</label>
        </div>
        
        <div class="field" >
          <input id="medicalname" type="text" class="input w50" value="" name="areaname" data-validate="required:请输入行政区域名称" onchange="doVerify()"/>
          <div class="tips" id="display"></div>
        </div>
      </div>
      
      <!-- <div class="form-group">
        <div class="label">
          <label>行政区域编码</label>
        </div>
        
        <div class="field">
          <input type="text" class="input w50" value="" name="areacode" data-validate="required:请输入行政区域编码" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>行政区域等级</label>
        </div>
        
        <div class="field">
        	<select name="arealevel" style="padding:5px 15px; border:1px solid #ddd;" onchange="changecate(this)" data-validate="required:请选择等级">
            <option value="">请选择行政区域等级</option>
            <option value="1">县</option>
            <option value="2">镇</option>
            <option value="3">村</option>
            <option value="4">组</option>
          </select>
          <div class="tips"></div>
        </div>
      </div> -->
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div> 
      
	  
    </form>
  </div>
</div>

</body>
</html>